package com.stylefeng.guns.modular.app.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.BusinessSub;
import com.stylefeng.guns.modular.app.service.IBusinessSubService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-08-02 21:57:14
 */
@Controller
@RequestMapping("/businessSub")
public class BusinessSubController extends BaseController {

    private String PREFIX = "/app/businessSub/";

    @Autowired
    private IBusinessSubService businessSubService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "businessSub.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/businessSub_add")
    public String businessSubAdd() {
        return PREFIX + "businessSub_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/businessSub_update/{businessSubId}")
    public String businessSubUpdate(@PathVariable Integer businessSubId, Model model) {
        BusinessSub businessSub = businessSubService.selectById(businessSubId);
        model.addAttribute("item",businessSub);
        LogObjectHolder.me().set(businessSub);
        return PREFIX + "businessSub_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return businessSubService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BusinessSub businessSub) {
    	businessSub.setCreateId(1);
    	businessSub.setCreateTime(new Date());
        businessSubService.insert(businessSub);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer businessSubId) {
        businessSubService.deleteById(businessSubId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BusinessSub businessSub) {
        businessSubService.updateById(businessSub);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{businessSubId}")
    @ResponseBody
    public Object detail(@PathVariable("businessSubId") Integer businessSubId) {
        return businessSubService.selectById(businessSubId);
    }
}
